{% extends "base.html" %}
{%- import "releases/header.html" as release_macros -%}

{%- block title -%}Releases - Docs.rs{%- endblock title -%}

{%- block header -%}
    {# These all have defaults so searches work #}
    {%
        call release_macros::header(
            title="Releases",
            description=description,
            tab=release_type,
            owner=owner.as_deref().unwrap_or_default()
        )
    %}
{%- endblock header -%}

{%- block topbar -%}
    {%- include "header/topbar.html" -%}
{%- endblock topbar -%}

{%- block body_classes -%}
centered
{%- endblock body_classes -%}

{%- block body -%}
    <div class="container">
        <div class="recent-releases-container">
            {%- block sort_by %}{% endblock sort_by -%}
            <ul>
                {# TODO: If there are no releases, then display a message that says so #}
                {%- for release in releases -%}
                    <li>
                    {%- match release -%}
                        {%- when ReleaseStatus::NotAvailable(name) -%}
                            <div class="release">
                                <div class="pure-g">
                                    <div class="pure-u-1 pure-u-sm-6-24 pure-u-md-5-24 name not-available">{{ name }}</div>
                                    <div class="pure-u-1 pure-u-sm-14-24 pure-u-md-16-24 description">Documentation not available on docs.rs</div>
                                </div>
                            </div>
                        {%- when ReleaseStatus::External(release) -%}
                            <a href="{{ release.href }}" class="release"> {#- -#}
                                <div class="pure-g"> {#- -#}
                                    <div class="pure-u-1 pure-u-sm-6-24 pure-u-md-5-24 name">
                                        {{- release.name -}}
                                    </div>

                                    <div class="pure-u-1 pure-u-sm-14-24 pure-u-md-16-24 description">
                                        {{- release.description -}}
                                    </div>

                                    <div class="pure-u-1 pure-u-sm-4-24 pure-u-md-3-24 date">
                                    </div>
                                </div> {#- -#}
                            </a>
                        {%- when ReleaseStatus::Available(release) -%}
                            {%- set release_params -%}
                            {%- set has_unyanked_releases = release.has_unyanked_releases.unwrap_or(true) -%}
                            {%- if release_type == "search" && has_unyanked_releases -%}
                                {%- set release_params = release.rustdoc_params().with_req_version(ReqVersion::Latest) -%}
                            {%- else -%}
                                {%- set release_params = release.rustdoc_params() -%}
                            {%- endif -%}
                            {%- set link -%}
                            {%- if release.rustdoc_status -%}
                                {% set link = release_params.rustdoc_url() -%}
                            {%- else -%}
                                {% set link = release_params.crate_details_url() -%}
                            {%- endif -%}
                            <a href="{{ link|safe }}" class="release"> {#- -#}
                                <div class="pure-g"> {#- -#}
                                    <div class="pure-u-1 pure-u-sm-6-24 pure-u-md-5-24 name">
                                        {{- release.name -}}
                                        -{{ release.version }}
                                        {%- if !has_unyanked_releases ~%}
                                            <span class="yanked" title="all releases of {{ release.name }} have been yanked">
                                                {{- crate::icons::IconTrash.render_solid(false, false, "") ~}}
                                                Yanked
                                            </span>
                                        {%- endif -%}
                                    </div> {#- -#}

                                    <div class="pure-u-1 pure-u-sm-14-24 pure-u-md-16-24 description">
                                        {{- release.description.as_deref().unwrap_or_default() -}}
                                    </div>

                                    {%- if release_type == "owner" -%}
                                        <div class="pure-u-1 pure-u-sm-4-24 pure-u-md-3-24 date" {% if let Some(build_time) = release.build_time -%}
                                            title="Published {{ build_time|timeformat }}" {%- endif -%}>
                                            {{- release.stars ~}}
                                            {{ crate::icons::IconStar.render_solid(false, false, "") -}}
                                        </div>
                                    {%- elif let Some(build_time) = release.build_time -%}
                                        <div class="pure-u-1 pure-u-sm-4-24 pure-u-md-3-24 date" {#~ -#}
                                            title="{{ build_time.format("%FT%TZ") }}">
                                            {{- build_time|timeformat -}}
                                        </div>
                                    {%- else -%}
                                        <div class="pure-u-1 pure-u-sm-4-24 pure-u-md-3-24 date">
                                            &mdash;
                                        </div>
                                    {%- endif -%}
                                </div> {#- -#}
                            </a>
                        {%- endmatch -%}
                    </li>
                {%- endfor -%}
            </ul> {#- -#}

            <div class="pagination">
                {% block pagination %}
                    {%- if show_previous_page -%}
                        <a class="pure-button pure-button-normal" href="/releases/{{ release_type.as_str() }}/{{ page_number - 1 }}">
                            {{ crate::icons::IconArrowLeft.render_solid(false, false, "") }} Previous Page
                        </a>
                    {%- endif -%}

                    {%- if show_next_page -%}
                        <a class="pure-button pure-button-normal" href="/releases/{{ release_type.as_str() }}/{{ page_number + 1 }}">
                            Next Page {{ crate::icons::IconArrowRight.render_solid(false, false, "") }}
                        </a>
                    {%- endif -%}
                {% endblock pagination %}
            </div>
        </div>
    </div>
{%- endblock body -%}

{%- block javascript -%}
    <script nonce="{{ csp_nonce }}" type="text/javascript" src="/-/static/keyboard.js?{{ build_slug }}"></script>
{%- endblock javascript -%}
